package MR;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ReceiveTable implements Writable,DBWritable {
    private String content;
    private int count;

    public ReceiveTable() {
    }

    public ReceiveTable(String content, int count) {

        this.content = content;
        this.count = count;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(this.count);
        Text.writeString(dataOutput,this.content);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.content = dataInput.readUTF();
        this.count = dataInput.readInt();
    }

    @Override
    public void write(PreparedStatement preparedStatement) throws SQLException {
        preparedStatement.setString(1,this.content);
        preparedStatement.setInt(2,this.count);
    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        this.content = resultSet.getString(1);
        this.count = resultSet.getInt(2);
    }
}
